package com.example.demo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.example.demo.entity.Banners;
import com.example.demo.service.IBannersService;
import com.example.demo.utils.PageResult;
import com.example.demo.utils.PassToken;
import com.example.demo.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.web.bind.annotation.*;


import static com.github.pagehelper.page.PageMethod.startPage;

/**
 * bannersController
 * 
 * @author ruoyi
 * @date 2025-03-27
 */
@RestController
@RequestMapping("/system/banners")
public class BannersController
{
    @Autowired
    private IBannersService bannersService;

    /**
     * 查询banners列表
     */
    @PassToken
    @GetMapping("/list")
    public ResponseResult list(Banners banners, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10")int pageSize)
    {
       // startPage();

        PageResult pageResult = bannersService.selectBannersList(banners,pageNum,pageSize);
        return  ResponseResult.createBySuccess(200,pageResult,"查询成功");
    }

    /**
     * 导出banners列表
     */

//    @Log(title = "banners", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Banners banners)
//    {
//        List<Banners> list = bannersService.selectBannersList(banners);
//        ExcelUtil<Banners> util = new ExcelUtil<Banners>(Banners.class);
//        util.exportExcel(response, list, "banners数据");
//    }

    /**
     * 获取banners详细信息
     */
    @GetMapping(value = "/{id}")
    public ResponseResult getInfo(@PathVariable("id") Long id)

    {
        Banners banners = bannersService.selectBannersById(id);
        return  ResponseResult.createBySuccess(200,banners,"查询成功");
    }

    /**
     * 新增banners
     */

    @PostMapping
    public ResponseResult add(@RequestBody Banners banners)
    {
        int i = bannersService.insertBanners(banners);
        if (i>0){
            return  ResponseResult.createBySuccess(200,"","添加成功");
        }else{
            return  ResponseResult.createByFail(200,"添加失败");
        }
    }

    /**
     * 修改banners
     */

    @PutMapping
    public ResponseResult edit(@RequestBody Banners banners)
    {
        int i =bannersService.updateBanners(banners);
        if (i>0){
            return  ResponseResult.createBySuccess(200,"","修改成功");
        }else{
            return  ResponseResult.createByFail(200,"修改失败");
        }
    }

    /**
     * 删除banners
     */

	@DeleteMapping("/{ids}")
    public ResponseResult remove(@PathVariable Long[] ids)
    {
        int i =bannersService.deleteBannersByIds(ids);
        if (i>0){
            return  ResponseResult.createBySuccess(200,"","删除成功");
        }else{
            return  ResponseResult.createByFail(200,"删除失败");
        }

    }
}
